<?php include "../public/header.php";?>
<?php include "../public/header_edit.php";?>
<body id="optPage">
<form class="layui-form layui-form-pane" id="commentForm">
    <div class="page-title"><div class="page-title-con"><span>任务执行</span><div class="move_title"></div><?php include "../public/sub.php";?></div></div>
    <div class="main-container">

        <div class="block-generic">


            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="edittits"><span>基本信息</span></div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label">任务名称</label>
                        <div class="layui-input-block">
                            <input type="text" id="name" readonly placeholder="请选择"   autocomplete="off" class="layui-input disabled">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label"><text>*</text>实际开始时间</label>
                        <div class="layui-input-block">
                            <input type="text" name="startdt" id="startdt" readonly placeholder="请选择" clearable  autocomplete="off" class="layui-input bdate_ymdhi_startdt">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label">完成比例%</label>
                        <div class="layui-input-block">
                            <input type="text" id="rate" name="rate" placeholder="请输入" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label">实际完成时间</label>
                        <div class="layui-input-block">
                            <input type="text" name="enddt" id="enddt" readonly placeholder="请选择" clearable  autocomplete="off" class="layui-input bdate_ymdhi_enddt">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item height_auto">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label label_textarea">任务执行说明</label>
                        <div class="layui-input-block">
                            <textarea id="explainzhi" name="explainzhi" placeholder="请输入" class="layui-textarea"></textarea>
                        </div>
                    </div>
                </div>
            </div>

            <?php include '../public/upinfo.php'?>
        </div>


    </div>
</form>
<script>
    var param_id = getQueryVariable('id') || 0;

    $("#commentForm").validate({
        rules: {
            startdt: {required: true},
        },
        messages:{
            startdt: {required: "请选择"},
        }
    });


    var jietype;
    layui.use(['laytp', 'form'], function() {
        var form = layui.form, layer = layui.layer;
        render_input_attr();

        facade.ajax({type: 'get', url: ask_task_zhi, data:{id:param_id}}).done(function(res){
            if (res.code === 2000) {
                var data = res.data.data;


                $('.bdate_ymdhi_startdt').datetimepicker({
                    language: 'zh-CN',//显示中文
                    format: 'yyyy-mm-dd hh:ii',//显示格式
                    initialDate: new Date(),//初始化当前日期
                    autoclose: true,//选中自动关闭
                    todayBtn: true,
                    endDate: new Date()
                });

                $('.bdate_ymdhi_enddt').datetimepicker({
                    language: 'zh-CN',//显示中文
                    format: 'yyyy-mm-dd hh:ii',//显示格式
                    initialDate: new Date(),//初始化当前日期
                    autoclose: true,//选中自动关闭
                    todayBtn: true,
                    endDate: new Date()
                }).on('changeDate',function () {
                    var rate = parseInt($("#rate").val()) || 0
                    if(rate != 100){
                        layer.confirm("<div class='tit'>任务完成，是否将完成比例修改为100%？</div>", {
                                title:'操作确认',
                                icon: 3,
                                area:['450px','220px'],
                                btn:['确定']
                            }, function(conindex){
                                $("#rate").val(100)
                                layer.close(conindex)
                            }
                        )
                    }
                });

                $("#name").val(data.name)
                $("#startdt").val(data.startdt)
                $("#enddt").val(data.enddt)
                $("#rate").val(data.rate)
                $("#explainzhi").val(data.explainzhi)



                public_upload_file_load('upload_files', res.data.files);
                render_date();
                render_from();
            }
        });



        form.on('submit(add)', function(data){
            var validRes = $("#commentForm").valid();
            if(!validRes){return false;}


            data.field.id = param_id;
            data.field.files = public_upload_file_value('upload_files');
            facade.ajax({url: ask_task_zhi, data:data.field}).done(function(res){
                if (res.code === 2000) {
                    dataPostTimeOut();
                }
            });

            return false;
        });

    });


</script>
</body>
</html>
